//引入必要模块
const express = require('express');
const mysql = require('../mysql');

//建立路由组
const router = express.Router();

//用户登录
router.get('/login',(req,res)=>{
    //获取传入的数据
    let body = req.query();

    //判断数据是否为空
    if(!body.uname){
        return res.send({code:401});
    }
    if(!body.upwd){
        return res.send({code:402});
    }

    //sql命令执行
    mysql.query('select * from xz_user where uname=? and upwd=?',[body.uname,body,upwd],(err,result)=>{
        if(err) throw err;
        if(result.length == 0){
            return res.send({code:301});
        }
        res.send({code:200});
    });
});

//用户列表
router.get('/list',(req,res)=>{
    mysql.query('select * from xz_user',[],(err,result)=>{
        if(err) throw err;
        res.send(result);
    });
});

//导出对象
module.exports = router;